/**
 * 
 */
package edu.bu.grocery.session;

import java.io.Serializable;

import edu.bu.grocerylist.model.GroceryList;
import edu.bu.grocerylist.model.GroceryListItem;
import edu.bu.grocerylist.model.GroceryUser;

/**
 * This object represents the user session info (currently logged in user, other session info)
 * @author donlanp
 *
 */
public class UserSession implements Serializable{
	

	private static final long serialVersionUID = -5775509617427744831L;
	
	private GroceryUser currentUser;
	private GroceryList currentGroceryList;
	private String unauthorizedUserName;
	private String unauthorizedUserSecurityQuestion;

	/**
	 * @return the currentUser
	 */
	public GroceryUser getCurrentUser() {
		return currentUser;
	}
	
	public GroceryList getCurrentGroceryList() {
		return currentGroceryList;
	}
	
	public void setCurrentGroceryList(GroceryList currentGroceryList) {
		this.currentGroceryList = currentGroceryList;
	}

	/**
	 * @param currentUser the currentUser to set
	 */
	public void setCurrentUser(GroceryUser currentUser) {
		this.currentUser = currentUser;
	}
	
	public String getCurrentUserName(){
		return (currentUser!=null)?currentUser.getEmail():unauthorizedUserName;
	}
	
	public void setCurrentUserName(String userName) throws Exception{
		if(currentUser!=null){
			throw new Exception("Invalid operation!");
		}
		unauthorizedUserName = userName;
	}
	
	public String getCurrentUserSecurityQuestion(){
		return (currentUser!=null)?currentUser.getSecurityQuestion():unauthorizedUserSecurityQuestion;
	}
	
	public void setCurrentUserSecurityQuestion(String securityQuestion) throws Exception{
		if(currentUser!=null){
			throw new Exception("Invalid operation!");
		}
		unauthorizedUserSecurityQuestion = securityQuestion;
	}
	
}
